package jmine.tec.subscription.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import jmine.tec.subscription.Publisher;
import jmine.tec.subscription.PublisherManager;

/**
 * {@link PublisherManager} simples que guarda os {@link Publisher} em um {@link ConcurrentHashMap}
 * 
 * @author takeshi
 */
public final class PublisherManagerImpl implements PublisherManager {

    private final Map<String, Publisher<?>> publishers = new ConcurrentHashMap<String, Publisher<?>>();

    /**
     * {@inheritDoc}
     */
    public Publisher<?> getPublisher(String name) {
        return this.publishers.get(name);
    }

    /**
     * {@inheritDoc}
     */
    public List<Publisher<?>> getPublishers() {
        return new ArrayList<Publisher<?>>(this.publishers.values());
    }

    /**
     * {@inheritDoc}
     */
    public void register(Collection<? extends Publisher<?>> registers) {
        for (Publisher<?> publisher : registers) {
            this.publishers.put(publisher.identification(), publisher);
        }
    }

}
